import java.util.List;

public class Leet24 {
    public static void main(String[] args) {
        ListNode head = new ListNode();
        ListNode re = head;
        for (int i = 0; i < 3; i++) {
            head.val = i+1;
            head.next = new ListNode();
            head = head.next;
        }
        head.val = 4;
        Leet24 l =  new Leet24();
        System.out.println(l.swapPairs(re));
    }
    public ListNode swapPairs(ListNode head) {
        ListNode re = head;
        if (head ==null||head.next==null)
            return head;
        ListNode temp1 = head.next;
        head.next = head.next.next;
        temp1.next = head;
        while (head.next!=null&&head.next.next!=null){
                ListNode temp = head.next;
                head.next = head.next.next;
                head.next.next = temp;
            head = head.next.next;
        }
        return re;
    }
}
